/**
 * Created with JetBrains WebStorm.
 * User: Ryan
 * Date: 13-8-16
 * Time: 下午11:18
 * To change this template use File | Settings | File Templates.
 */

(function(){
    window.Application = window.Application || {};

    var loadPage;

    loadPage = function(page){
        var xhr = $.get("/page/" + page);
        xhr.done(function(response){
            $("#page-content").html(response);
            if(page == "home") page = "";
            $("#breadcrumbs .breadcrumb .active").html(page.split("?")[0]);
        });
        xhr.fail(function(data, err){

        });
    };

    $(window).on('hashchange', function(e) {
        var page = e.originalEvent.newURL.split("#")[1];
        if(page) loadPage(page);
    });

    $("document").ready( function(){
        var page = window.location.hash.split("#").slice(1).join("#");
        if(page) loadPage(page);
    });
})();
